<?php
// 本文档自动生成，仅供测试运行
class ContentAction extends Action
{

	/**
	 * ------------------------------
	 * 预处理
	 * ------------------------------
	 */
	function _initialize(){
		if( !isset($_SESSION['adm_name']) or !isset($_SESSION['isAdmin']) ) $this->redirect('Index/login');
	}
    /**
	 * ------------------------------
	 * 众筹产品
	 * ------------------------------
	 */
	function news(){
	
		import("@.ORG.Page");
		$count	= M('news')->count();
		$Page	= New Page($count,10);
		$show	= $Page->show();
		$list = M('news')->order('xu desc,id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		foreach($list as $k=>$v){
			$list[$k]['renshu']=M('anli')->where("fenlei=".$v['id']."")->count();
		}
	    $this->assign('list', $list);
		$this->assign('page', $show);
		$this->assign('pagetitle', '众筹产品');
	
		$this->display();
	 }
	
	function editnews(){
        $id = intval($_GET['id']);
		if($id==''){
		     $this->assign('pagetitle', '添加众筹产品');
		}else{
			 $list = M('news')->find($id);
			 $this->assign($list);
			 $this->assign('type', 'edit');
			 $this->assign('pagetitle', '修改众筹产品');
		}
		$this->display('news_edit');
	}
   
   function donews(){
   	    header("Content-Type:text/html; charset=utf-8");
		if( !M()->autoCheckToken($_POST) ) $this->error('禁止站外提交！');
		unset($_POST['__hash__']);
		foreach ($_POST as $k => $v) {
			if($v == '') unset($_POST[$k]);
		}
		$_POST['time']=time();
		
		if($_POST['id']){
				if( M('news')->save($_POST) ){
					
					$this->assign('jumpUrl', U('Content/news'));
					$this->success('修改成功！');
				}else{
					$this->error('没有任何改动　或　修改失败！');
				}
		}else{
		      if( M('news')->add($_POST) ){
					$this->assign('jumpUrl', U('Content/news'));
					$this->success('添加成功！');
			  }else{
					$this->error('添加失败！');
			  }
		}
	}
	
	function delnews(){
	    $ids = $_POST['ids'];
		$del = M('news')->where("id IN ($ids)")->delete();
        echo $del?'1':'0';
	}
 
 



    /**
	 * ------------------------------
	 * 作品
	 * ------------------------------
	 */
	function anli(){
	
		import("@.ORG.Page");
		$count	= M('anli')->count();
		$Page	= New Page($count,15);
		$show	= $Page->show();
		$list = M('anli')->order('xu desc,id desc')->limit($Page->firstRow.','.$Page->listRows)
						     ->select();
		foreach($list as $k=>$v){
			$anlifenlei=M('news')->find($v['fenlei']);
			$list[$k]['fenlei']=$anlifenlei['name'];
			if($v['zhuangtai']==1){
				$list[$k]['zhuangtai']="是";
			}else{
				$list[$k]['zhuangtai']="否";
			}
		}

	    $this->assign('list', $list);
		$this->assign('page', $show);
		$this->assign('pagetitle', '客户');
	
		$this->display();
	 }
	
	function editanli(){
        $id = intval($_GET['id']);
		$list1 = M('news')->select();
	    $this->assign('list1', $list1);
		if($id==''){
		     $this->assign('pagetitle', '添加客户');
		}else{
			 $list = M('anli')->find($id);
			 foreach($list as $k=>$v){
				 if(get_magic_quotes_gpc()!='-1' || get_magic_quotes_gpc()==true){
					$list[$k]=stripslashes($v); 
				 } 
	         }
			 $this->assign($list);

			 $this->assign('type', 'edit');
			 $this->assign('pagetitle', '修改客户');
		}
		$this->display('anli_edit');
	}
   
   function doanli(){
   	    header("Content-Type:text/html; charset=utf-8");
		if( !M()->autoCheckToken($_POST) ) $this->error('禁止站外提交！');
		unset($_POST['__hash__']);
		foreach ($_POST as $k => $v) {
			if($v == '') unset($_POST[$k]);
		}
		$_POST['time']=time();
		if($_POST['id']){
				if( M('anli')->save($_POST) ){
					
					$this->assign('jumpUrl', U('Content/anli'));
					$this->success('修改成功！');
				}else{
					$this->error('没有任何改动　或　修改失败！');
				}
		}else{
		      if( M('anli')->add($_POST) ){
					$this->assign('jumpUrl', U('Content/anli'));
					$this->success('添加成功！');
			  }else{
					$this->error('添加失败！');
			  }
		}
	}
	
	function delanli(){
	    $ids = $_POST['ids'];
		$del = M('anli')->where("id IN ($ids)")->delete();
        echo $del?'1':'0';
	}
 
	
	function tuianli(){
	    $ids = $_POST['ids'];
		$tui['zhuangtai']=1;
		$del = M('anli')->where("id IN ($ids)")->save($tui);
        echo $del?'1':'0';
	}
 
	function qutuianli(){
	    $ids = $_POST['ids'];
		$tui['zhuangtai']=0;
		$del = M('anli')->where("id IN ($ids)")->save($tui);
        echo $del?'1':'0';
	}
	function daochukehu(){
		$stadata = M('anli')->field('id,name,dianhua,fenlei,time')->select();
		foreach($stadata as $k=>$v){
			$xinghao=D('news')->find($v['fenlei']);
			$stadata[$k]['fenlei']=$xinghao['name'];
		}
		$stanum   = count($stadata);
		/** Include PHPExcel */
		require_once './admin/Lib/Action/PHPExcel.php';
		// Create new PHPExcel object
		$objPHPExcel = new PHPExcel();
		// Set document properties
		$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
									 ->setLastModifiedBy("Maarten Balliauw")
									 ->setTitle("Office 2007 XLSX Test Document")
									 ->setSubject("Office 2007 XLSX Test Document")
									 ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
									 ->setKeywords("office 2007 openxml php")
									 ->setCategory("Test result file");
		// Add some data
		$objPHPExcel->setActiveSheetIndex(0)
					->setCellValue('A1', 'ID号')
					->setCellValue('B1', '客户姓名')
					->setCellValue('C1', '联系电话')
					->setCellValue('D1', '意向型号')
					->setCellValue('E1', '登记时间');
		// Miscellaneous glyphs, UTF-8
		for($i=0; $i<$stanum; $i++) {
			$j = $i+2;
			$objPHPExcel->setActiveSheetIndex(0)
					->setCellValue('A'.$j, $stadata[$i]['id'])
					->setCellValue('B'.$j, $stadata[$i]['name'])
					->setCellValue('C'.$j, $stadata[$i]['dianhua'])
					->setCellValue('D'.$j, $stadata[$i]['fenlei'])
					->setCellValue('E'.$j, date('Y-m-d H:i:s',$stadata[$i]['time']));
		}
		//设置单元格宽度
        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
        $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(15);
        $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(15);
        $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
		//设置居中
        $objPHPExcel->getActiveSheet()->getStyle('A1:E'.($i+1))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		// Rename worksheet
		$objPHPExcel->getActiveSheet()->setTitle('Simple');
		// Set active sheet index to the first sheet, so Excel opens this as the first sheet
		$objPHPExcel->setActiveSheetIndex(0);
		//$user = iconv('utf-8','gb2312',$user);
		// Redirect output to a client’s web browser (Excel5)
		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment;filename=kehu'.date('YmdHis',time()).'.xls');
		header('Cache-Control: max-age=0');

		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		$objWriter->save('php://output');
		
		exit;

	}
 
    /**
	 * ------------------------------
	 * 顶部焦点图片
	 * ------------------------------
	 */
	function jiaodian(){
	
		import("@.ORG.Page");
		$count	= M('jiaodian')->count();
		$Page	= New Page($count,15);
		$show	= $Page->show();
		$list = M('jiaodian')->order('xu desc,id desc')->limit($Page->firstRow.','.$Page->listRows)
						     ->select();
	    $this->assign('list', $list);
		$this->assign('page', $show);
		$this->assign('pagetitle', '幻灯片列表');
	
		$this->display();
	 }
	
	function editjiaodian(){
        $id = intval($_GET['id']);
		if($id==''){
		     $this->assign('pagetitle', '添加幻灯片');
		}else{
			 $list = M('jiaodian')->find($id);
				foreach($list as $k=>$v){
				 if(get_magic_quotes_gpc()!='-1' || get_magic_quotes_gpc()==true){
					$list[$k]=stripslashes($v); 
				 } 
				}
			 $this->assign($list);
			 
			 $this->assign('type', 'edit');
			 $this->assign('pagetitle', '修改幻灯片');
		}
		$this->display('jiaodian_edit');
	}
   
   function dojiaodian(){
	   
   	    header("Content-Type:text/html; charset=utf-8");
		if( !M()->autoCheckToken($_POST) ) $this->error('禁止站外提交！');
		unset($_POST['__hash__']);
		foreach ($_POST as $k => $v) {
			if($v == '') unset($_POST[$k]);
		}
		
		
		if($_POST['id']){
				if( M('jiaodian')->save($_POST) ){
					$this->assign('jumpUrl', U('Content/jiaodian'));
					$this->success('修改成功！');
				}else{
					$this->error('没有任何改动　或　修改失败！');
				}
		}else{
		      if( M('jiaodian')->add($_POST) ){
					$this->assign('jumpUrl', U('Content/jiaodian'));
					$this->success('添加成功！');
			  }else{
					$this->error('添加失败！');
			  }
		}
	}
	
	function deljiaodian(){
	    $ids = $_POST['ids'];
		$del = M('jiaodian')->where("id IN ($ids)")->delete();
        echo $del?'1':'0';
	}

    /**
	 * ------------------------------
	 * 二级顶部图片
	 * ------------------------------
	 */
	function erjijiaodian(){
	
		import("@.ORG.Page");
		$count	= M('erjijiaodian')->count();
		$Page	= New Page($count,15);
		$show	= $Page->show();
		$list = M('erjijiaodian')->order('id desc')->limit($Page->firstRow.','.$Page->listRows)
						     ->select();
	    $this->assign('list', $list);
		$this->assign('page', $show);
		$this->assign('pagetitle', '大图列表');
	
		$this->display();
	 }
	
	function editerjijiaodian(){
        $id = intval($_GET['id']);
		if($id==''){
		     $this->assign('pagetitle', '添加大图');
		}else{
			 $list = M('erjijiaodian')->find($id);
				foreach($list as $k=>$v){
				 if(get_magic_quotes_gpc()!='-1' || get_magic_quotes_gpc()==true){
					$list[$k]=stripslashes($v); 
				 } 
				}
			 $this->assign($list);
			 
			 $this->assign('type', 'edit');
			 $this->assign('pagetitle', '修改大图');
		}
		$this->display('erjijiaodian_edit');
	}
   
   function doerjijiaodian(){
	   
   	    header("Content-Type:text/html; charset=utf-8");
		if( !M()->autoCheckToken($_POST) ) $this->error('禁止站外提交！');
		unset($_POST['__hash__']);
		foreach ($_POST as $k => $v) {
			if($v == '') unset($_POST[$k]);
		}
		
		
		if($_POST['id']){
				if( M('erjijiaodian')->save($_POST) ){
					$this->success('修改成功！');
				}else{
					$this->error('没有任何改动　或　修改失败！');
				}
		}else{
		      if( M('erjijiaodian')->add($_POST) ){
					$this->success('添加成功！');
			  }else{
					$this->error('添加失败！');
			  }
		}
	}
	
	function delerjijiaodian(){
	    $ids = $_POST['ids'];
		$del = M('erjijiaodian')->where("id IN ($ids)")->delete();
        echo $del?'1':'0';
	}

  
	
}
?>